#include<iostream>
#include<algorithm>
#include<string>

using namespace std;
//           0 1 2 3 4 5 6 7 8 9
int cnt[] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int n;
int a[] = {9, 8, 7, 5, 4, 1}; //数字
int b[] = {6, 7, 3, 5, 4, 2}; // 火柴
int c[100005];
bool flag = false;

void dfs(int step, int left) //step 选了几个数， left 还剩几个火柴
{
    if (left < 2 * (n - step)) return;
    if (flag)
        return;
    if (left != 0 && left < 2)
        return;
    if (step >= n) {
        if (left == 0) {
            for (int i = 0; i < n; i++)
                cout << c[i];
            cout << endl;
            flag = true;
            return;
        } else
            return;
    }

    for (int i = 0; i < 6; i++) {
        c[step] = a[i];
        dfs(step + 1, left - b[i]);
    }

}

int main() {
    int t;
    cin >> t;
    while (t--) {
        cin >> n;
        string s;
        cin >> s;
        int num = 0;
        flag = false;
        for (int i = 0; i < s.length(); i++) {
            num += cnt[s[i] - '0'];
        }
        dfs(0, num);
    }
    return 0;
}